﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;
using DevExpress.XtraEditors;
using QLTV_Public;
using QLTV_BLL;

namespace QLTV_GiaoDien
{
    public partial class frm_TaiLieu_TheLoai : DevExpress.XtraEditors.XtraForm
    {
        public frm_TaiLieu_TheLoai()
        {
            InitializeComponent();
        }
        public void Get_Load(int ma)
        {
            txt_Load.Text = ma.ToString();
        }
        TheLoai_BLL theLoai_bll = new TheLoai_BLL();
        private void frm_TaiLieu_TheLoai_Load(object sender, EventArgs e)
        {
            gridControl1.DataSource = theLoai_bll.LayDuLieu();
            txt_Load.Hide();
        }
        private void btn_Them_Click(object sender, EventArgs e)
        {
            frm_TaiLieu_TheLoai_Them f = new frm_TaiLieu_TheLoai_Them();
            f.Flag = 0;
            f.MyGetData = new frm_TaiLieu_TheLoai_Them.GetInt(Get_Load);
            f.ShowDialog();
        }

        private void btn_Sua_Click(object sender, EventArgs e)
        {
            frm_TaiLieu_TheLoai_Them f = new frm_TaiLieu_TheLoai_Them();
            f.Flag = 1;
            f.MyGetData = new frm_TaiLieu_TheLoai_Them.GetInt(Get_Load);
            f.MaTheLoai = Convert.ToInt32(gridView1.GetRowCellValue(gridView1.FocusedRowHandle,"Mã Thể Loại").ToString());
            f.TenTheLoai =gridView1.GetRowCellValue(gridView1.FocusedRowHandle, "Tên Thể Loại").ToString();
            f.GhiChu = gridView1.GetRowCellValue(gridView1.FocusedRowHandle, "Ghi Chú").ToString();
            f.ShowDialog();
        }

        private void btn_Thoat_Click(object sender, EventArgs e)
        {
            this.Close();
        }

        NhatKy_BLL nhatKy_bll = new NhatKy_BLL();
        NhatKy_Public nk = new NhatKy_Public();
        TrungGian tg = new TrungGian();
        private void btn_Xoa_Click(object sender, EventArgs e)
        {
            TheLoai_public tl = new TheLoai_public();
            tl.MaTheLoai = Convert.ToInt32(gridView1.GetRowCellValue(gridView1.FocusedRowHandle, "Mã Thể Loại").ToString());
            tl.TenTheLoai = gridView1.GetRowCellValue(gridView1.FocusedRowHandle, "Tên Thể Loại").ToString();
            if (XtraMessageBox.Show("Bạn có muốn xóa tên thể loại: '" + tl.TenTheLoai + "' có mã là: '" + tl.MaTheLoai + "' này không?", "Thông Báo", MessageBoxButtons.OKCancel, MessageBoxIcon.Question) == DialogResult.OK)
            {
                theLoai_bll.delete_theLoai(tl);
                //
                string d = DateTime.Now.ToString();
                nk.MaNV = tg.MaNV;
                nk.NgayGio = d;
                nk.HanhDong = "Xóa";
                nk.MoTa = "Xóa thông tin Thể loại: '" + tl.TenTheLoai+ "'";
                nhatKy_bll.insert_nhatKy(nk, nk, nk, nk);
                //
                frm_TaiLieu_TheLoai_Load(sender,e);
            }
        }
        public delegate void GetInt(int kt);
        public GetInt MyGetData;
        private void gridControl1_DoubleClick(object sender, EventArgs e)
        {
            MyGetData(Convert.ToInt32(gridView1.GetRowCellValue(gridView1.FocusedRowHandle, "Mã Thể Loại")));
            this.Close();
        }

        private void btn_Chon_Click(object sender, EventArgs e)
        {
            MyGetData(Convert.ToInt32(gridView1.GetRowCellValue(gridView1.FocusedRowHandle, "Mã Thể Loại")));
            this.Close();
        }

        private void txt_Load_TextChanged(object sender, EventArgs e)
        {
            if (txt_Load.Text == "1")
            {
                frm_TaiLieu_TheLoai_Load(sender,e);
                txt_Load.Text = "0";
            }
        }


    }
}